package mao.leetcode.offer;

import java.util.Scanner;

/**
 * @author Totoro
 * @date 2020/8/12
 * @explain:
 */
public class interview56_1 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr= {7,1,7,2,6,6,3,1};
        solution.singleNumbers(arr);

        Scanner scanner = new Scanner(System.in);


    }

   static class Solution {
        public int[] singleNumbers(int[] nums) {
            int xor  = 0;
            for(int i=0;i<nums.length;i++){
                xor^=nums[i];
            }
            int mask=1;
            //老老实实，不要搞骚操作。
            while((mask & xor ) <= 0 ) mask<<=1;

            int xorA=0,xorB=0;
            for(int i=0;i<nums.length;i++){
                if((nums[i] & mask) > 0){
                    xorA^=nums[i];
                }else{
                    xorB^=nums[i];
                }
            }
            return new int[]{xorA,xorB};
        }
    }
}
